//
//  NGBaseNavigationBarView.swift
//  NingguoForum
//
//  Created by zhengsw on 2022/11/22.
//  Copyright © 2022 zhengsw. All rights reserved.
//

import UIKit

protocol NGBaseNavigationBarViewDelegate: AnyObject {
    func backAction ()
}

class NGBaseNavigationBarView: UIView {
    weak open var delegate: NGBaseNavigationBarViewDelegate?
    var backBtn: UIButton!
    lazy var titleLabel: UILabel = {
        let width = 100.0
        var titleLabel = UILabel(frame: CGRectMake((KSCREEN_WIDTH-width)/2.0, KDevice_StatusBar_Height, width, 44))
        titleLabel.textColor = .white
        titleLabel.textAlignment = .center
        self.addSubview(titleLabel)
        return titleLabel
    }()
    override init(frame: CGRect) {
        super.init(frame: frame)
        backgroundColor = kTHEME_COLOR
        
        backBtn = UIButton(frame: CGRect(x: 10, y: KDevice_StatusBar_Height, width: 44, height: 44))
        backBtn.setImage(UIImage(named: "home_back"), for: .normal)
        backBtn.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        self.addSubview(backBtn)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setTitle(title:String) {
        titleLabel.text = title
    }
    
    @objc func backAction() {
        delegate?.backAction()
    }
    func setBackBtnHidden(hidden: Bool) {
        backBtn.isHidden = hidden
    }
}
